package uk.ac.cloudcomputing;

import java.io.Serializable;

public class Chart implements Serializable {

	private String graph;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1106037452989253007L;

	public Chart() {
		setGraph(setCompleteGraph());
	}

	public String setCompleteGraph() {
		StringBuffer sb = new StringBuffer();
		String x = "Year";
		String bar1 = "Wins";
		String bar2 = "Losses";
		int endYear = 2011;
		int begYear = 2008;
		int diff = endYear - begYear + 1;
		int inc = 0;
		
		sb.append("data.addColumn('string', '" + x + "');");
		sb.append("data.addColumn('number', '" + bar1 + "');");
		sb.append("data.addColumn('number', '" + bar2 + "');");
		sb.append("data.addRows(" + diff +  ");");
		
		for (int i = begYear; i <= endYear; ++i, ++inc) {
			for (int j = 0; j <= 2; ++j) {
				if (j == 0)
					sb.append("data.setValue(" + inc + ", " + j + ", '" + i + "');");
				if (j == 1)
					sb.append("data.setValue(" + inc + ", " + j + ", 1000);");
				if (j == 2)
					sb.append("data.setValue(" + inc + ", " + j + ", 400);");				
			}
		}
		return sb.toString();
	}

	// Getters

	public String getGraph() {
		return graph;
	}

	// Setters

	public void setGraph(String g) {
		this.graph = g;
	}
}
